package com.itheima.appserver.controller;

import com.itheima.appserver.service.UserIndexService;
import com.itheima.commons.model.vo.CountInfoVo;
import com.itheima.commons.model.vo.DistributionVo;
import com.itheima.commons.model.vo.QueryActiveRetentionVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("management/dashboard")
public class UserIndexController {

    @Autowired
    private UserIndexService userIndexService;

    /**
     * 注册用户分布，行业top、年龄、性别、地区
     *
     * @param start
     * @param end
     * @return
     */
    @GetMapping("distribution")
    public ResponseEntity queryUserInfo(@RequestParam("sd") Long start,
                                        @RequestParam("ed") Long end) {
        DistributionVo distributionVo = userIndexService.queryUserInfo(start, end);
        return ResponseEntity.ok(distributionVo);
    }

    /**
     * 概要统计信息
     *
     * @return
     */
    @GetMapping("summary")
    public ResponseEntity countInfo() {
        CountInfoVo countInfoVo = userIndexService.countInfo();
        return ResponseEntity.ok(countInfoVo);
    }

    /**
     * 新增、活跃用户、次日留存率
     *
     * @param start
     * @param end
     * @param type
     * @return
     */
    @GetMapping("users")
    public ResponseEntity queryActiveRetention(@RequestParam("sd") Long start,
                                               @RequestParam("ed") Long end,
                                               @RequestParam("type") Integer type) {
        QueryActiveRetentionVo queryActiveRetentionVo = userIndexService.queryActiveRetention(start, end, type);
        return ResponseEntity.ok(queryActiveRetentionVo);
    }
}
